import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class SSBomberA here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class SSBomberA extends Attachable
{
    /**
     * Act - do whatever the SSBomberA wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    private static final int detectRange = 901;
    private static final double acceleration = 1.5;//pixels/s^2
    boolean init = false;
    private double momentum = 0;
    private double direction = 0;
    private boolean toDelete = false;
    public SSBomberA(){
    super(4, new GreenfootImage("SSBomber.png"));
    }
    
    public void act() 
    {
        if(!init){
            setCoords(getX()-Play.getTrueX(), getY()-Play.getTrueY());
            init = true;
        }
        Player p = Play.p;
        
        double D = getDistance(Play.getTrueX()-500, Play.getTrueY()-300, X,Y);
        if(D < detectRange){
        turnTowards(p.getX(),p.getY());
        if(p.getX() > getX()&& Math.abs(Px) < 10){
            if(Px < 0){
             Px+=.5;
            }else{
              Px+=.1;
            }
            
        }else if(p.getX() < getX()&& Math.abs(Px) < 10){
            
             if(Px > 0){
             Px-=.5;
            }else{
              Px-=.1;
            }
            
        }
        if(p.getY() > getY()&& Math.abs(Py) < 10){
            
             if(Py < 0){
             Py+=1;
            }else{
              Py+=.1;
            }
            
        }else if(p.getY() < getY()&& Math.abs(Py) < 10){
           
             if(Py > 0){
             Py-=1;
            }else{
              Py-=.1;
            }
            
        }
            /*if(p.Px > Px){
              Px +=.2;
            }else if(p.Px < Px){
             Px -=.2;
            }*/
        }
        if(isTouching(Player.class)){
        toDelete = true;
        }
        super.act();
        if(toDelete){
         getWorld().addObject(new Explosion(), getX(), getY());   
         getWorld().removeObject(this);
        }
    }
    private double getDistance(double x, double y,double x1, double y1){
       double diffX = Math.abs(Math.abs(x)-Math.abs(x1));
       double diffY = Math.abs(Math.abs(y)-Math.abs(y1));
       
       System.out.println(Math.sqrt(Math.pow(diffX,2)+Math.pow(diffY,2)));
       
       return Math.sqrt(Math.pow(diffX,2)+Math.pow(diffY,2));
    }
      
}
